library(chemistr)

Creating a Scatter Plot

# Here is where you input your data for your two variables.  
Independent <- c(1, 2, 4, 8) #This is the X-axis values
Dependent <- c(10, 100, 1000, 100000) #This is the Y-axis values
data <- data_frame(Independent, Dependent) #This is a data frame.  This links all your variables into a single table.
# Here is where you create your first graph.   
chem_scatter(data = data, xvar = Independent, yvar = Dependent, xlab = "Axis Label", ylab = "Axis Label") #This is the info for making the graph.  If you are making a new graph, the variables will need to reflect this.
fit1 <- lm(Dependent ~ Independent, data = data)  #This is how we get the fit values out.  If you change the variables you're graphing, the same will need to be done here.
summary(fit1) #This will show the fit parameters in your document
n <- length(Dependent) #This calculates the number of datapoints that went into calculating the standard error
slope<-summary(fit1)$coef[[2]] #This creates a variable for the slope
se_slope<-summary(fit1)$coef[[4]] #This creates a variable for the standard error of the slope
Intercept<-summary(fit1)$coef[[1]] #This creates a variable for the intercept
se_intercept<-summary(fit1)$coef[[3]]  #This creates a variable for the standard error of the intercept
CI_Slope <- se_slope*qt(0.975,df=n-2) #This caluclates the 95% confidence interval for the slope


ismayc/chemistr documentation built on Feb. 4, 2023, 12:44 p.m.